import { Session, Local } from '/@/utils/storage';

export function getUrl(type: string = 'baseURL') {
	/* 
    imgUploadUrl: "http://dev.20180807.com:8764/api/file/uploadsource"
    mediaUrl: "dev.20180807.com"
    url: "http://47.99.69.23:8764"
    rtmpUrl: "rtmp://dev.20180807.com:1984/live/"
    wsUrl: "ws:///47.99.69.23:8764/ws"
    */

	let org = Local.get('org') || {};
	let { url, rtcUrl } = org;

	if (url && rtcUrl) {
		url = url.trim();
		rtcUrl = rtcUrl.trim();
	}

	let curProtocol = location.protocol;

	let curWsProtocol = curProtocol == 'https:' ? 'wss:' : 'ws:';

	let urlMap: any = {
		baseURL: `${curProtocol}//${url}`,
		wsUrl: `${curWsProtocol}//${url}/ws`,
		audioStreamWs: `${curWsProtocol}//${url}/webAudioStream`,
		imgUploadUrl: `${curProtocol}//${url}/api/file/uploadsource`,
		webrtcUrl: `${rtcUrl}`,
	};

	return urlMap[type];
}